let regexType = [
  {
    label: "非空",
    regex: ".+",
    value: 0,
  },
  {
    label: "字符串",
    value: 1,
    regex: "[A-Za-z0-9]{1,64}",
  },
  {
    label: "大写字符串",
    value: 2,
    regex: "[A-Z]{1,64}",
  },
  {
    label: "小写字符串",
    value: 3,
    regex: "[a-z]{1,64}",
  },
  {
    label: "数字",
    value: 4,
    regex: "[0-9]{1,64}",
  },
  {
    label: "数字范围",
    value: 5,
    regex: "d{1,5}",
  },
  {
    label: "日期",
    value: 6,
    regex: "d{4}-d{1,2}-d{1,2}",
  },
  {
    label: "时间",
    value: 7,
    regex: "d{4}-d{1,2}-d{1,2}s{1}d{2}:d{2}:d{2}",
  },
  {
    label: "IP",
    value: 8,
    regex:"(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])[.]){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])",
  },
  {
    label: "其他",
    value: 9,
    regex: "[A-Za-z0-9]{1,64}",
  }
];

let addVerifyDlg = {
  label: "新增",
  type: "button",
  actionType: "dialog",
  level: "primary",
  align: "left",
  dialog: {
    title: "新增校验",
    size: "lg",
    body: {
      type: "form",
      api: {
        method: "post",
        url: "/_dev/verify/add",
        data: {
          interface_id: "${interface_id}",
          "&": "$$"
        },
      },
      body: [
        {
          type: "group",
          body: [
            {
              label: "参数名",
              type: "input-text",
              name: "verify_param",
              required: true,
              source: {
                method: "get",
                url: "/_dev/interface/parser_param",
                data: {
                  id: "${interface_id}",
                },
              },
              clearable: true,
              showCounter: true,
              required: true,
              validations: {
                isUrlPath: true,
                minLength: 1,
                maxLength: 64
              }
            },
            {
              type: "select",
              name: "regex_type",
              label: "正则模板",
              clearValueOnEmpty: true,
              showCounter: true,
              options: regexType,
              onEvent: {
                change: {
                  actions: [
                    {
                      actionType: "setValue",
                      componentId: "verify_regex",
                      args: {
                        value: "${event.data.selectedItems.regex}",
                      },
                    },
                    {
                      actionType: "setValue",
                      componentId: "verify_desc",
                      args: {
                        value: "${event.data.selectedItems.label}",
                      },
                    },
                  ],
                },
              },
            },
          ]
        },
        {
          type: "input-text",
          name: "verify_regex",
          id: "verify_regex",
          maxLength: 256,
          clearable: true,
          required: true,
          label: "正则",
          clearValueOnEmpty: true,
          showCounter: true,
        },
        {
          type: "input-text",
          name: "verify_desc",
          id: "verify_desc",
          maxLength: 256,
          required: true,
          clearable: true,
          label: "描述",
          clearValueOnEmpty: true,
          showCounter: true,
        },
      ],
    },
    actions: [
      {
        label: "取消",
        type: "button",
        actionType: "close",
        level: "default",
      },
      {
        label: "确认",
        type: "button",
        actionType: "submit",
        level: "primary",
      },
    ],
  },
};

let editVerifyDlg = {
  label: "编辑",
  type: "button",
  actionType: "dialog",
  level: "primary",
  align: "left",
  dialog: {
    title: "编辑校验",
    size: "lg",
    body: {
      type: "form",
      api: {
        method: "post",
        url: "/_dev/verify/edit",
        data: {
          id: "${id}",
          "&": "$$",
        },
      },
      body: [
        {
          type: "group",
          body: [
            {
              label: "参数名",
              type: "input-text",
              name: "verify_param",
              required: true,
              disabled: true,
            },
            {
              type: "select",
              name: "regex_type",
              label: "正则模板",
              clearValueOnEmpty: true,
              showCounter: true,
              options: regexType,
              onEvent: {
                change: {
                  actions: [
                    {
                      actionType: "setValue",
                      componentId: "verify_regex",
                      args: {
                        value: "${event.data.selectedItems.regex}",
                      },
                    },
                    {
                      actionType: "setValue",
                      componentId: "verify_desc",
                      args: {
                        value: "${event.data.selectedItems.label}",
                      },
                    },
                  ],
                },
              },
            },
          ]
        },
        {
          type: "input-text",
          name: "verify_regex",
          id: "verify_regex",
          maxLength: 256,
          clearable: true,
          required: true,
          label: "正则",
          clearValueOnEmpty: true,
          showCounter: true,
        },
        {
          type: "input-text",
          name: "verify_desc",
          id: "verify_desc",
          maxLength: 256,
          required: true,
          clearable: true,
          label: "描述",
          clearValueOnEmpty: true,
          showCounter: true,
        },
      ],
    },
    actions: [
      {
        label: "取消",
        type: "button",
        actionType: "close",
        level: "default",
      },
      {
        label: "确认",
        type: "button",
        actionType: "submit",
        level: "primary",
      },
    ],
  },
};

let delVerifyButton = {
  label: "删除",
  type: "button",
  actionType: "ajax",
  level: "danger",
  visibleOn: "${verify_status===0}",
  confirmText: "确认删除校验",
  api: {
    method: "post",
    url: "/_dev/verify/del",
    data: {
      id: "${id}",
    },
  },
};

let disableVerifyButton = {
  label: "停用",
  type: "button",
  actionType: "ajax",
  level: "warning",
  visibleOn: "${verify_status===1}",
  confirmText: "确认停用参数校验[${verify_param}]？",
  api: {
    method: "post",
    url: "/_dev/verify/edit",
    data: {
      id: "${id}",
      verify_status: "0",
    },
  },
};

let enableVerifyButton = {
  label: "启用",
  type: "button",
  actionType: "ajax",
  level: "success",
  visibleOn: "${verify_status===0}",
  confirmText: "确认启用参数校验[${verify_param}]？",
  api: {
    method: "post",
    url: "/_dev/verify/edit",
    data: {
      id: "${id}",
      verify_status: "1",
    },
  },
};

let verifyTable = {
  type: "crud",
  perPage: 10,
  affixHeader: true,
  headerToolbar: [addVerifyDlg, "statistics", "pagination"],
  footerToolbar: [],
  tital: "",
  data: {
    interface_id: "${id}",
  },
  api: {
    method: "get",
    url: "/_dev/verify/list",
    data: {
      interface_id: "${interface_id}",
      page: "1",
      prePage: "100"
    },
  },

  columns: [
    {
      name: "verify_param",
      label: "参数名",
      width: 100,
    },
    {
      name: "verify_regex",
      label: "正则表达式",
    },
    {
      name: "verify_desc",
      label: "描述",
    },
    {
      type: "operation",
      label: "操作",
      buttons: [editVerifyDlg, delVerifyButton, enableVerifyButton, disableVerifyButton],
      width: 200,
    },
  ],
};


export { verifyTable }